<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>动态停止</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<style type="text/css">
.main {
	margin-right: 15px;
}

ul {
	list-style: none;
}

.icon-list li a {
	cursor: pointer;
}
</style>
</head>
<body>
	<div class="main">
		<!--工具栏-->
		<div id="floatHead" class="toolbar-wrap">
			<div class="toolbar">
				<div class="box-wrap">
					<a class="menu-btn"></a>
					<div class="l-list">
						<ul class="icon-list">
							<li><a class="all" onclick="selectAll()"><i></i><span>全选</span></a></li>
							<li><a class="list" onclick="stopMore()"><i></i><span>批量停止</span></a></li>
						</ul>
					</div>
					<div class="r-list">
						<input id="search" class="keyword" /> <a class="btn-search"
							onclick="searchItem()">查询</a>
					</div>
				</div>
			</div>
		</div>
		<!--/工具栏-->

		<table id="tt"></table>
	</div>

	<script
		src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" 
		type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	var contextPath = '<%=request.getContextPath()%>';
	$(function(){
		getTableList();
		$(window).resize(function() {
			//延迟执行,防止多次触发
			setTimeout(function() {
				$('#tt').datagrid('resize');
			}, 100);
		});
	})
	
		/*获取数据列表*/
	function getTableList() {
		var search=$('#search').val();
		$('#tt').datagrid({
	        //height: $('body').height() - 270,
	        nowrap: true,
	        striped: true,
	        collapsible: false,
	        remoteSort: false,
	        selectOnCheck: false,
	        checkOnSelect: false,
	        singleSelect: true,
	        fitColumns: true,
	        url: contextPath + "/bg/DC101.do?dc_status=3,5&search="+encodeURI(search)+"&rnd=" +Math.random(),
	        columns: [[
	            {
	                field:'CK',
	                title:'选择',
	                align:'center',
	                width:100,
	                formatter:function(value,row,index){
	                	return '<input name="check" data-code="'+row.CODE+'" type="checkbox"/>';                	
	                }
	            },
	            {
	                field: 'CODE',
	                title: '动态编码',
	                align: 'center',
	                width: 100
								},
	            {
	                field: 'NAME',
	                title: '动态名称',
	                align: 'center',
	                width: 100,
								},
	            {
	                field: 'AUTHOR',
	                title: '作者',
	                align: 'center',
	                width: 100
								},
	            {
	                field: 'CREATE_DATE',
	                title: '发布时间',
	                align: 'center',
	                width: 100
								},
	            {
	                field: 'STATUS_NAME',
	                title: '动态状态',
	                align: 'center',
	                width: 100
								},
				{
					field: 'OTHER3',
					title: '动态查看',
					align: 'center',
					width: 100,
					formatter: function (id, row, index) {
					    return '<button type="button" onclick="show(\'' +
								row.CODE +
								'\')" class="btn">查看</button>';
					}
									},
	            {
	                field: 'OTHER1',
	                title: '动态停止',
	                align: 'center',
	                width: 100,
	                formatter: function (id, row, index) {
	                    return '<button type="button" onclick="stop(\'' +
                        row.CODE +
                        '\')" class="btn">停止</button>';
	                }
								}
								]],
	        pagination: true,
	        pageSize: 10,
	        pageList: [10, 15, 30, 40]
	    });		
	}
	//全选
	function selectAll(){
		var unCheck=true;
		$('input[name="check"]').each(function(){
			if(!$(this).prop('checked')){
				$(this).prop("checked", true);
				unCheck=false;
			}
		})
		if(unCheck){
			$('input[name="check"]').prop("checked", false);
		}
	}
	//查询
	function searchItem(){
		getTableList();
	}
	//批量停止
		function stopMore(){
		var codeList='';
		if($('input[name="check"]:checked').size()<1){
			$.messager.show({title:'提示',msg:'请选择需要停止的动态！',showType:'slide'});
			return;
		}
		$('input[name="check"]:checked').each(function(){
			codeList+=$(this).attr("data-code")+",";
		})	
		codeList=codeList.substring(0,codeList.length-1);
		stop(codeList);
	}
	//停止
		function stop(codeList){
		$.ajax({
			url : contextPath + "/bg/DC109.do",
			data : {"codeList":codeList,"rnd":Math.random()},
			dataType : 'json',
			success : function(data, textStatus, jqXHR) {
				if(data.status=='true'){
					$.messager.show({title:'提示',msg:'停止成功！',showType:'slide'});
					getTableList();
				}else{
					$.messager.show({title:'提示',msg:'停止失败！',showType:'slide'});
				}
			}
		})
	}
	//查看
	function show(code){
		location.href = contextPath + "/bg/dynamic_edit.do?action=edit&show=1&code="
		+ code + "&rnd=" + Math.random();
	}
	</script>
</body>
</html>